package com.wangjiyuan.giftshuo.widget.coustomview;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.TextView;

import com.wangjiyuan.giftshuo.R;

/**
 * Created by QXL on 2016/11/18.
 */

public class RectangleBac extends TextView {
    private Paint mPaint;
    private int strokeWidth=1;
    private int backgroundColor=getResources().getColor(R.color.customPink);

    public RectangleBac(Context context) {
        super(context);
        init(null,0);
    }

    public RectangleBac(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs,0);
    }

    public RectangleBac(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(attrs,defStyleAttr);
    }

    private void init(AttributeSet attrs, int defStyleAttr) {
        TypedArray typedArray = getContext().getResources().obtainAttributes(attrs, R.styleable.RectangleBac);
        strokeWidth= (int) typedArray.getDimension(R.styleable.RectangleBac_strokewidth,strokeWidth);
        backgroundColor=typedArray.getColor(R.styleable.RectangleBac_backgroundColor,backgroundColor);
        typedArray.recycle();

        mPaint=new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setColor(backgroundColor);
        mPaint.setStrokeWidth(strokeWidth);
        Paint.Style stroke = Paint.Style.STROKE;//设置画笔样式，值描边
        mPaint.setStyle(stroke);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        int width = getWidth();
        int height = getHeight();
        canvas.drawRect(0,0,width,height,mPaint);
    }
}
